package com.jhx.myremotecontrol

import android.hardware.ConsumerIrManager
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.jhx.library.app.AppActivity
import com.jhx.library.setOnSingleClickListener
import com.jhx.myremotecontrol.databinding.ActivityMainBinding


class MainActivity : AppActivity<ActivityMainBinding>() {

    override fun getViewBinding() = ActivityMainBinding.inflate(layoutInflater)

    override fun initView() {
        ConsumerIrManagerApi.getConsumerIrManager(this@MainActivity)
        if (!ConsumerIrManagerApi.hasIrEmitter()){
            ToastUtils.showShort("红外功能不可用")
            return
        }
        LogUtils.e(ConsumerIrManagerApi.getCarrierFrequencies())
        binding.run {
            btOnOff.setOnSingleClickListener {
                ConsumerIrManagerApi.transmit(38000,
                    NecPattern.buildPattern(
                        0xB2,
                        0x7B,
                        0xE0));
                ToastUtils.showShort("已发送")
            }

            bt1.setOnSingleClickListener {
                ConsumerIrManagerApi.transmit(38000,
                    NecPattern.buildPattern(
                        0XB2,
                        0X1F,
                        0XD8));
                ToastUtils.showShort("已发送")
            }

            bt2.setOnSingleClickListener {
                ConsumerIrManagerApi.transmit(38000,
                    NecPattern.buildPattern(
                        0X08,
                        0XE6,
                        0X41));
                ToastUtils.showShort("已发送")
            }

        }
    }

}